package com.fap.core.bo;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fap.core.bo.define.BoDefineRepository;

@Component
public class BoRepository {

	@Autowired
	private BoActionMapper _boAction;
	
	private static BoRepository _instance;
	
	@Resource(name="boFactory")
	private BoFactory _factory;
	
	@PostConstruct
	public void init(){
		_instance = this;
		_instance._boAction = this._boAction;
		_instance._factory = this._factory;
		BusinessObject.action = this._boAction;
	}
	
	public static BoRepository getInstance(){
		return _instance;
	}
	
	public BusinessObject getObject(String boTag, int id){
		BusinessObject bo = _factory.createByTag(boTag);
		bo.setId(String.valueOf(id));
		return _boAction.getObject(bo);
	}
	
	public List<BusinessObject> query(BusinessObject bo, int pageId, int pageSize){
		return _boAction.query(bo,pageId, pageSize);
	}
	
	public void insert(BusinessObject bo){
		_boAction.insert(bo);
	}

//	public void update(BusinessObject bo){
//		_boAction.update(bo);
//	}

	public void delete(BusinessObject bo){
		_boAction.delete(bo);
	}
}
